package com.cq.hd.member.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbAppUserApi;
import com.cq.hd.member.api.dto.*;
import com.cq.hd.member.api.vo.AppUserPageVo;

import com.cq.hd.member.api.vo.AppUserVo;
import com.cq.hd.member.service.TbAppUserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * app用户表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@RestController
public class TbAppUserController implements TbAppUserApi {

    @Autowired
    private TbAppUserService appUserService;

    @ApiOperation(value = "注册用户列表")
    @ApiImplicitParam(name = "appUserPageDto", value = "实体", required = true, paramType = "query", dataType = "AppUserPageDto")
    @ApiResponse(response = AppUserPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<AppUserPageVo>> pageAppUser(AppUserPageDto appUserPageDto) {
        return ResultGenerator.success(appUserService.pageAppUser(appUserPageDto));
    }

    @ApiOperation(value = "根据手机号获取用户信息")
    @ApiImplicitParam(name = "mobile", value = "手机号", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = AppUserVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppUserVo> getByMobile(String mobile) {
        return ResultGenerator.success(appUserService.getByMobile(mobile));
    }

    @ApiOperation(value = "根据openId获取用户信息")
    @ApiImplicitParam(name = "openId", value = "openId", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = AppUserVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppUserVo> getByOpenId(String openId) {
        return ResultGenerator.success(appUserService.getByOpenId(openId));
    }

    @ApiOperation(value = "根据用户id获取用户信息")
    @ApiImplicitParam(name = "userIds", value = "用户id集合", required = true, paramType = "query", dataType = "String")
    @ApiResponse(response = AppUserVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<AppUserVo>> listByUserIds(@RequestBody List<Long> userIds) {
        return ResultGenerator.success(appUserService.listByUserIds(userIds));
    }

    @ApiOperation(value = "用户注册")
    @ApiImplicitParam(name = "appUserPageDto", value = "实体", required = true, paramType = "body", dataType = "AppUserPageDto")
    @ApiResponse(response = AppUserPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppUserVo> register(@RequestBody LoginDto loginDto) {
        return ResultGenerator.success(appUserService.register(loginDto));
    }

    @ApiOperation(value = "根据用户id获取用户信息")
    @ApiImplicitParam(name = "id", value = "实体", required = true, paramType = "query", dataType = "Long")
    @ApiResponse(response = AppUserPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<AppUserVo> getById(long id) {
        return ResultGenerator.success(appUserService.getAppUserById(id));
    }

    @ApiOperation(value = "根据日期查询新注册的用户数")
    @Override
    public Result<Integer> getNewCountByDate(String startTime, String endTime) {
        return ResultGenerator.success(appUserService.getNewCountByDate(startTime, endTime));
    }

    @ApiOperation(value = "给经纪人增加佣金账户余额")
    @Override
    public Result<Boolean> addCommissionAmt(Long userId, BigDecimal commissionAmt) {
        return ResultGenerator.success(appUserService.addCommissionAmt(userId, commissionAmt));
    }

    @ApiOperation(value = "更新商户本金，商户补贴和经纪人佣金，添加商户资金流水和经纪人佣金流水，统计商家与经纪人的累计结算分销佣金")
    @Override
    public Result<Boolean> updateOrderSettleAmt(@RequestBody OrderSettleUpdateDto orderSettleUpdateDto) {
        return ResultGenerator.success(appUserService.updateOrderSettleAmt(orderSettleUpdateDto));
    }

    @ApiOperation(value = "根据用户id更新unionid")
    @Override
    public Result<Boolean> updateUnionidById(Long id, String unionid) {
        return ResultGenerator.success(appUserService.updateUnionidById(id, unionid));
    }

    @ApiOperation(value = "根据unionid获取用户数据")
    @Override
    public Result<AppUserVo> getByUnionid(String unionid) {
        return ResultGenerator.success(appUserService.getByUnionid(unionid));
    }

    @ApiOperation(value = "修改登录密码")
    @Override
    public Result<Boolean> updatePwd(@RequestBody AppUserPwdUpdateDto appUserPwdUpdateDto) {
        return ResultGenerator.success(appUserService.updatePwd(appUserPwdUpdateDto));
    }
}
